package com.heyqing.topic.ThirdMax_0414;

import java.util.*;
import java.util.stream.Collectors;

/**
 * ClassName:ThirdMax
 * Package:com.heyqing.topic.ThirdMax_0414
 * Description:
 *
 * @Date:2024/9/29
 * @Author:Heyqing
 */
public class ThirdMax {
    public int thirdMax(int[] nums) {
        List<Integer> list = Arrays.stream(nums).boxed().collect(Collectors.toSet()).stream().collect(Collectors.toList());
        Collections.sort(list);
        return list.size() >= 3 ? list.get(list.size() - 3) : list.get(list.size() - 1);
    }
}
